package com.example.bms.order.service.impl;

import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.utils.PageUtils;
import com.example.common.utils.Query;

import com.example.bms.order.dao.PurchaseDao;
import com.example.bms.order.entity.PurchaseEntity;
import com.example.bms.order.service.PurchaseService;
import org.springframework.util.ObjectUtils;


@Service("purchaseService")
public class PurchaseServiceImpl extends ServiceImpl<PurchaseDao, PurchaseEntity> implements PurchaseService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<PurchaseEntity> queryWrapper = new QueryWrapper<PurchaseEntity>();
        String name = (String) params.get("key");
        String sid = (String) params.get("sid");
        String shid = (String) params.get("shid");
        String pid = (String) params.get("pid");
        String wid = (String) params.get("wid");

        if (!ObjectUtils.isEmpty(name)) {
            queryWrapper.eq("phid", name);
        }

        if (!ObjectUtils.isEmpty(pid)) {
            queryWrapper.or().eq("pid", pid);
        }

        if (!ObjectUtils.isEmpty(sid)) {
            queryWrapper.or().eq("sid", sid);
        }

        if (!ObjectUtils.isEmpty(shid)) {
            queryWrapper.or().eq("shid", shid);
        }

        if (!ObjectUtils.isEmpty(wid)) {
            queryWrapper.or().eq("wid", wid);
        }


        queryWrapper.orderByAsc("time");



        IPage<PurchaseEntity> page = this.page(
                new Query<PurchaseEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }

}